package com.qfedu.fmmall.controller;

import com.qfedu.fmmall.service.ProductCommentsService;
import com.qfedu.fmmall.service.ProductService;
import com.qfedu.fmmall.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;


/**
 * 商品
 *
 * @author liuyadi
 */
@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供商品信息相关的接口", tags = "商品管理")
public class ProductController {
    private ProductService productService;
    private ProductCommentsService productCommentsService;

    public ProductController(ProductService productService, ProductCommentsService productCommentsService) {
        this.productService = productService;
        this.productCommentsService = productCommentsService;
    }

    @GetMapping("/detail-info/{pid}")
    @ApiOperation("商品基本信息查询")
    public ResultVO getProductBasicInfo(@PathVariable("pid") String pid) {
        ResultVO productBasicInfo = productService.getProductBasicInfo(pid);
        return productBasicInfo;
    }

    @GetMapping("/detail-params/{pid}")
    @ApiOperation("商品参数信息查询")
    public ResultVO getProductParams(@PathVariable("pid") String pid) {
        ResultVO productParamsById = productService.getProductParamsById(pid);
        return productParamsById;
    }

    @GetMapping("/detail-comments/{pid}")
    @ApiOperation("商品评价信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNum", value = "当前页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页显示条数", required = true)
    })
    public ResultVO getProductComments(@PathVariable("pid") String pid, int pageNum, int limit) {
        ResultVO resultVO = productCommentsService.listCommentsByProductId(pid, pageNum, limit);
        return resultVO;
    }
}